<style scoped>
    .main {
        height: 100%;
    }
</style>

<template>
    <div class="main">
        <Main :options="options">
            <router-view></router-view>
        </Main>
    </div>
</template>

<script>
import Main from '@/components/layout/theme1'
import { mapActions } from 'vuex'
import { unit } from '@/api/platform'

export default {
  data () {
    return {
      router: this.$route,
      options: {
        treeData: {
          show: true,
          data: [],
          data2: []
        }
      }
    }
  },
  components: {
    Main
  },
  computed: {
    selectId () {
      return this.$store.state.app.menuSelectId
    }
  },
  methods: {
    ...mapActions([
      'getUserInfo',
      'getPhpMenusData',
      'getJavaMenusData',
      'setBreadCrumb'
    ]),
    getTreeData () {
      unit({ size: 1000 }).then(ret => {
        let data = ret.data.results
        let data2 = []
        data.forEach(item => {
          item.title = item.name
          item.children = []
          item.expand = true
          let ax = JSON.parse(JSON.stringify(item))
          if (ax.v_count > 0) {
            ax.title = ax.title + '(' + ax.v_count + ')'
          }
          data2.push(ax)
        })
        this.options.treeData.data = this.$common.toTree(data, 'children', 'id', 'pid')
        this.options.treeData.data2 = this.$common.toTree(data2, 'children', 'id', 'pid')
      })
    }
  },
  mounted () {
    // this.getUserInfo().then(resx => {})
    // TODO 如果是java菜单还需要调用综合菜单
    if (this.$config.phpMenu) {
      console.log(this.selectId, '22223112')
      this.getPhpMenusData(this.selectId)
    } else {
      this.getJavaMenus(22)
    }
    this.getTreeData()
  },
  watch: {
    router (router) {
      console.log(router)
    }
  }
}
</script>
